package JavaSE.CODE.javaOO;

public class encapsulation {
    public static void main(String[] args) {
        Person p = new Person();
        //p.age = 10;(×)
        System.out.println(p.getAge());
        p.setAge(10);
        System.out.println(p.getAge());
    }
}

class Person{

    private int age;
    private int id;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public char getSex() {
        return sex;
    }

    public void setSex(char sex) {
        this.sex = sex;
    }

    private char sex;

    //func
    public int getAge(){
        return this.age;
    }

    public boolean setAge(int age){
        if(age>120||age<0)
            return false;
        this.age = age;
        return true;
    }

}
